jQuery(function($) {
	$("#accordion").accordion();

	$("input:submit, a, button", "#buttonSet").button();

	$('button', "#buttonSet").click(function() {
		$.blockUI({
			message : $('#loginForm')
		});
		setTimeout($.unblockUI, 2000);
	});

});


jQuery(function() {
	// validate signup form on keyup and submit
	var validator = $("#signupform").validate({
		rules : {
			firstname : "required",
			lastname : "required",
			username : {
				required : true,
				minlength : 2,
				remote : "users.php"
			},
			password : {
				required : true,
				minlength : 5
			},
			password_confirm : {
				required : true,
				minlength : 5,
				equalTo : "#password"
			},
			email : {
				required : true,
				email : true,
				remote : "emails.php"
			},
			dateformat : "required",
			terms : "required"
		},
		messages : {
			firstname : "Enter your firstname",
			lastname : "Enter your lastname",
			username : {
				required : "Enter a username",
				minlength : jQuery.format("Enter at least {0} characters"),
				remote : jQuery.format("{0} is already in use")
			},
			password : {
				required : "Provide a password",
				rangelength : jQuery.format("Enter at least {0} characters")
			},
			password_confirm : {
				required : "Repeat your password",
				minlength : jQuery.format("Enter at least {0} characters"),
				equalTo : "Enter the same password as above"
			},
			email : {
				required : "Please enter a valid email address",
				minlength : "Please enter a valid email address",
				remote : jQuery.format("{0} is already in use")
			},
			dateformat : "Choose your preferred dateformat",
			terms : " "
		},
		// the errorPlacement has to take the table layout into account
		errorPlacement : function(error, element) {
			if (element.is(":radio"))
				error.appendTo(element.parent().next().next());
			else if (element.is(":checkbox"))
				error.appendTo(element.next());
			else
				error.appendTo(element.parent().next());
		},
		// specifying a submitHandler prevents the default submit, good for the
		// demo
		submitHandler : function() {
			alert("submitted!");
		},
		// set this class to error-labels to indicate valid fields
		success : function(label) {
			// set &nbsp; as text for IE
			label.html("&nbsp;").addClass("checked");
		}
	});

	// propose username by combining first- and lastname
	$("#username").focus(function() {
		var firstname = $("#firstname").val();
		var lastname = $("#lastname").val();
		if (firstname && lastname && !this.value) {
			this.value = firstname + "." + lastname;
		}
	});

});


jQuery(function() {
	
	function loadGrid() {
		var mydata = [
	  		{id:"1",invdate:"2010-05-24",name:"test",note:"note",tax:"10.00",total:"2111.00"} ,
	  		{id:"2",invdate:"2010-05-25",name:"test2",note:"note2",tax:"20.00",total:"320.00"},
	  		{id:"3",invdate:"2007-09-01",name:"test3",note:"note3",tax:"30.00",total:"430.00"},
	  		{id:"4",invdate:"2007-10-04",name:"test",note:"note",tax:"10.00",total:"210.00"},
	  		{id:"5",invdate:"2007-10-05",name:"test2",note:"note2",tax:"20.00",total:"320.00"},
	  		{id:"6",invdate:"2007-09-06",name:"test3",note:"note3",tax:"30.00",total:"430.00"},
	  		{id:"7",invdate:"2007-10-04",name:"test",note:"note",tax:"10.00",total:"210.00"},
	  		{id:"8",invdate:"2007-10-03",name:"test2",note:"note2",amount:"300.00",tax:"21.00",total:"320.00"},
	  		{id:"9",invdate:"2007-09-01",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"},
	  		{id:"11",invdate:"2007-10-01",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
	  		{id:"12",invdate:"2007-10-02",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
	  		{id:"13",invdate:"2007-09-01",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"},
	  		{id:"14",invdate:"2007-10-04",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
	  		{id:"15",invdate:"2007-10-05",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
	  		{id:"16",invdate:"2007-09-06",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"},
	  		{id:"17",invdate:"2007-10-04",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
	  		{id:"18",invdate:"2007-10-03",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
	  		{id:"19",invdate:"2007-09-01",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"},
	  		{id:"21",invdate:"2007-10-01",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
	  		{id:"22",invdate:"2007-10-02",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
	  		{id:"23",invdate:"2007-09-01",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"},
	  		{id:"24",invdate:"2007-10-04",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
	  		{id:"25",invdate:"2007-10-05",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
	  		{id:"26",invdate:"2007-09-06",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"},
	  		{id:"27",invdate:"2007-10-04",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
	  		{id:"28",invdate:"2007-10-03",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
	  		{id:"29",invdate:"2007-09-01",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"}
	  	];
	  
		jQuery("#gridGrouping").jqGrid({
			data: mydata,
			datatype: "local",
			height: 'auto',
			rowNum: 30,
			rowList: [10,20,30],
		   	colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
		   	colModel:[
		   		{name:'id',index:'id', width:60, sorttype:"int"},
		   		{name:'invdate',index:'invdate', width:90, sorttype:"date", formatter:"date"},
		   		{name:'name',index:'name', width:100, editable:true},
		   		{name:'amount',index:'amount', width:80, align:"right",sorttype:"float", formatter:"number", editable:true},
		   		{name:'tax',index:'tax', width:80, align:"right",sorttype:"float", editable:true},		
		   		{name:'total',index:'total', width:80,align:"right",sorttype:"float"},		
		   		{name:'note',index:'note', width:150, sortable:false}		
		   	],
		   	pager: "#pgridGrouping",
		   	viewrecords: true,
		   	sortname: 'name',
		   	grouping:true,
		   	groupingView : {
		   		groupField : ['name'],
		   		groupColumnShow : [false]
		   	},
		   	caption: "Hide Grouping Column"
		});
		
		
	}
	
	
	$("#gridBtn").click(loadGrid);
});


jQuery(function() {
	$("button[rel]").overlay({mask: '#000', effect: 'apple'});

	//setup exposing
	$("#ball").click(function()  {

		var el = $(this);

		el.expose({
			// grow the ball when exposing starts
			onBeforeLoad: function() {
				el.animate({width: 298});
			},

			// shrink the ball when exposing closes
			onBeforeClose: function() {
				el.animate({width: 130});
			}
		});
	});
});


jQuery(function($) {
	var setting = {
		data: {
			simpleData: {
				enable: true
			}
		}
	};

	var zNodes =[
		{ id:1, pId:0, name:"Custom Icon 01", open:true, iconOpen:"script/jQuery1.7.2/ztree/css/img/diy/1_open.png", iconClose:"script/jQuery1.7.2/ztree/css/img/diy/1_close.png"},
		{ id:11, pId:1, name:"leaf node 01", icon:"script/jQuery1.7.2/ztree/css/img/diy/2.png"},
		{ id:12, pId:1, name:"leaf node 02", icon:"script/jQuery1.7.2/ztree/css/img/diy/3.png"},
		{ id:13, pId:1, name:"leaf node 03", icon:"script/jQuery1.7.2/ztree/css/img/diy/5.png"},
		{ id:2, pId:0, name:"Custom Icon 02", open:true, icon:"script/jQuery1.7.2/ztree/css/img/diy/4.png"},
		{ id:21, pId:2, name:"leaf node 01", icon:"script/jQuery1.7.2/ztree/css/img/diy/6.png"},
		{ id:22, pId:2, name:"leaf node 02", icon:"script/jQuery1.7.2/ztree/css/img/diy/7.png"},
		{ id:23, pId:2, name:"leaf node 03", icon:"script/jQuery1.7.2/ztree/css/img/diy/8.png"},
		{ id:3, pId:0, name:"no Custom Icon", open:true },
		{ id:31, pId:3, name:"leaf node 01"},
		{ id:32, pId:3, name:"leaf node 02"},
		{ id:33, pId:3, name:"leaf node 03"}
	];

	$.fn.zTree.init($("#treeDemo"), setting, zNodes);
});


jQuery(function($) {
	$('.fancybox-thumbs').fancybox({
		prevEffect : 'none',
		nextEffect : 'none',

		closeBtn  : false,
		arrows    : false,
		nextClick : true,

		helpers : {
			thumbs : {
				width  : 50,
				height : 50
			}
		}
	});
});


